﻿using System.Web.Http;
using System.Web.Http.Dispatcher;
using System.Linq;
using System.Web.Http.Description;
using Autofac;
using System.Reflection;
using SDF.Core.Infrastructure;
using System.Web.Http.ExceptionHandling;
using System.Web.Mvc;
using SDF.Plugin.Misc.SAPAdapter.App_Start;

namespace SDF.Plugin.Misc.SAPAdapter
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "sapapi/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            ////exception logger 
            //config.Services.Add(typeof(IExceptionLogger), new SimpleExceptionLogger());
            ////exception handler
            //config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());


            //we will get JSON by default, but it will still allow you to return XML if you pass text/xml as the request Accept header
            var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
            config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            GlobalConfiguration.Configuration.EnsureInitialized();
        }
    }
}
